package cn.jy.boot.config;

import cn.jy.boot.pojo.User;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
//标注一个类为配置类
@Configuration
//扫描mapper包到spring容器
@MapperScan("cn.jy.boot.mapper")
public class MybatisPlusConfig {

//    @Bean("user1")  //向spring容器中注入一个 方法的返回值类型的一个bean 对象
//    public User getUser(){
//    User user = new User();
//    user.setName("zhangsan");
//        return user;
//    }

//    <bean id = "getban" class = "cn.jy.boot.pojo.User">
//    <property name="name" value="zhangsan"></property>
//    </bean>

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
//        添加分页拦截器
//        addInnerInterceptor 添加一个plus的内部拦截器

        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        //添加乐观锁的拦截器
        mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        return mybatisPlusInterceptor;
    }

}
